package ${package}.controller.sil;

import com.imydao.common.core.domain.R;
import com.imydao.common.core.web.controller.BaseController;
import com.imydao.common.core.web.page.TableDataInfo;
import com.imydao.common.log.annotation.Log;
import com.imydao.common.log.enums.BusinessType;
import com.imydao.common.security.annotation.RequiresPermissions;
import ${package}.domain.sil.${ClassName};
import ${package}.domain.sil.dto.${ClassName}Dto;
import ${package}.domain.sil.dto.${ClassName}SearchDto;
import ${package}.domain.sil.vo.${ClassName}Vo;
import ${package}.service.sil.${ClassName}Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * ${tableComment}
 *
 * @author ${author} ${email}
 * @since ${version} ${date}
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/v1/${pathname}")
@Api(tags="${tableComment}")
@AllArgsConstructor
public class ${ClassName}Controller extends BaseController {

    private final ${ClassName}Service ${className}Service;

    /**
     * 列表
     * @param dto 分页请求参数
     * @return 分页列表
     */
    @RequiresPermissions("${permname}:list")
    @GetMapping("list")
    @ApiOperation("分页列表")
    public R<TableDataInfo<${ClassName}>> list(${ClassName}SearchDto dto){
        List<${ClassName}> list = ${className}Service.findList(dto);
        return R.ok(getDataTable(list));
    }

    /**
     * 新增
     * @param dto 新增对象
     * @return 主键id
     */
    @ApiOperation("新增")
    @RequiresPermissions("${permname}:add")
    @Log(title = "${tableComment}", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public R<Long> add(@RequestBody @Valid ${ClassName}Dto dto){
        return R.ok(${className}Service.add(dto));
    }

    /**
     * 编辑
     * @param dto 编辑对象
     * @return 主键id
     */
    @ApiOperation("编辑")
    @RequiresPermissions("${permname}:edit")
    @Log(title = "${tableComment}", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public R<Integer> edit(@RequestBody @Valid ${ClassName}Dto dto){
        return R.ok(${className}Service.edit(dto));
    }

    /**
     * 根据Id查询详情
     *
     * @param id 主键id
     * @return 详情
     */
    @ApiOperation(value = "详情")
    @RequiresPermissions("${permname}:detail")
    @GetMapping("detail/{id}")
    public R<${ClassName}Vo> detail(@PathVariable("id") Long id) {
        return R.ok(${className}Service.detail(id));
    }

    /**
     * 删除
     * @param ids 主键id 多个逗号分割
     * @return 已删除数量
     */
    @ApiOperation("删除")
    @RequiresPermissions("${permname}:delete")
    @Log(title = "${tableComment}", businessType = BusinessType.DELETE)
    @GetMapping("delete/{ids}")
    public R<Integer> delete(@PathVariable("ids") Long[] ids){
        return R.ok(${className}Service.delete(ids));
    }
}